<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" id="aid">
<head>
  <meta charset="utf-8">
  <title>客户管理 / 人员组管理</title>
  <link rel="stylesheet" href="../../../css/layui.css" media="all">	
  <link rel="stylesheet" type="text/css" href="../../../css/common.css"/>
	<link rel="stylesheet" type="text/css" href="../../../zTree/zTreeStyle/zTreeStyle.css"/>
</head>
<body class="inner-body layui-row layui-col-space10" style="background:#f2f2f2;position: relative; ">
<div class="body-left treeDiv" style="-webkit-box-orient: vertical;">
	<!-- <div style="margin: 10px 0px 5px 5px; "><button type="button" class="layui-btn layui-btn-primary" style="width: 185px;">+ 新建部门</button></div> -->
	<div><ul id="treeDemo" class="ztree"></ul></div>
	
</div>
<!-------默认表格开始----------->
<div class="body-right">	 
	<div class="tableHtml" style="height: 100%;background: #FFFFFF; min-width: 800px;">
		<div class="top-btn">
			<div class="layui-btn-group">
				<button class="layui-btn" id="addBtn">新建组</button>
				<button class="layui-btn" id="addPersonBtn">添加员工到组</button>
				<button class="layui-btn" id="detailBtn">详情</button>
				<button class="layui-btn" id="delBtn">批量移除</button>
		 	</div>
		 	<div class="search-btn-group layui-form">
				<input type="text"  autocomplete="off" class="layui-input layui-input_" placeholder="请输入员工组名称">
				<input type="text"  autocomplete="off" class="layui-input layui-input_" placeholder="请输入学工号">
		 		<button class="layui-btn layui-btns">查询</button>
			</div>
		</div>
		<div class="tableDiv" >
			<table id="layui-table" lay-filter="tableBox" class="layui-table"></table>
		</div>
	</div>
</div>

<!-----------------默认表格结束------------>

</body>
<script type="text/html" id="barDemo">
	{{# if(d.status == "0"){ }}
	<span class="layui-badge-dot ayui-bg-orange"></span><a class="" lay-event="choose">未授权</a>
	{{# } }}
	{{# if(d.status == "1"){ }}
	<span class="layui-badge-dot layui-bg-green"></span><a class="" lay-event="shouquan" style="cursor: pointer;">已授权</a>
	{{# } }}
</script>
	
<script src='../../../layui.all.js'></script>
<script src="../../../js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="../../../zTree/jquery.ztree.all.js" type="text/javascript"></script>
<script src="../../../zTree/jquery.ztree.exhide-3.5.min.js" type="text/javascript"></script>
<script src="../../../zTree/MtrSearchZTree.js" type="text/javascript"></script>
<script type="text/javascript">
	var setting = {
		view: {
		            addHoverDom: addHoverDom,//显示操作图标
		            removeHoverDom: removeHoverDom,//移除图标
		            selectedMulti: false
		          },
		         data: {
		             simpleData: {
		                 enable: true
		             }
		         },
		         callback: {
		             onRename: zTreeOnRename,//修改
		             onRemove: zTreeOnRemove,//删除
		             onClick: zTreeOnClickRight,
					 beforeEditName: beforeEditName,
					 beforeRemove: beforeRemove,
					 beforeRename: beforeRename,
		 
		         },
		         edit: {
		             enable: true,
		             showRemoveBtn: true,
		             showRenameBtn: true,
		             removeTitle: "删除",
		             renameTitle: "修改"
		         }
	};
		
		var zNodes =[
			{ name:"安徽银通物联有限公司", open:true,
				children: [
					{ name:"合肥一中"},
					{ name:"合肥二中"},
					{ name:"合肥三中"},
					{ name:"合肥四中"},
					{ name:"合肥五中"},									
				]},
		];

		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			new MtrSearchZTree();
		});
		
		var log, className = "dark";
		var newCount = 1;
		function addHoverDom(treeId, treeNode) {
			var sObj = $("#" + treeNode.tId + "_span");
			if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
			var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
				+ "' title='add node' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var btn = $("#addBtn_"+treeNode.tId);
			if (btn) btn.bind("click", function(){
				var zTree = $.fn.zTree.getZTreeObj("treeDemo");
				zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
				return false;
			});
		};
		function removeHoverDom(treeId, treeNode) {
			$("#addBtn_"+treeNode.tId).unbind().remove();
		};
		function zTreeOnRename(e, treeId, treeNode, isCancel) {
			showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" onRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
		}
		function zTreeOnRemove(e, treeId, treeNode) {
			showLog("[ "+getTime()+" onRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
		}
		function showLog(str) {
			if (!log) log = $("#log");
			log.append("<li class='"+className+"'>"+str+"</li>");
			if(log.children("li").length > 8) {
				log.get(0).removeChild(log.children("li")[0]);
			}
		}
		function getTime() {
			var now= new Date(),
			h=now.getHours(),
			m=now.getMinutes(),
			s=now.getSeconds(),
			ms=now.getMilliseconds();
			return (h+":"+m+":"+s+ " " +ms);
		}
		
		function beforeEditName(treeId, treeNode) {
			className = (className === "dark" ? "":"dark");
			showLog("[ "+getTime()+" beforeEditName ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.selectNode(treeNode);
			setTimeout(function() {
				if (confirm("进入节点 '" + treeNode.name + "'编辑状态?")) {
					setTimeout(function() {
						zTree.editName(treeNode);
					}, 0);
				}
			}, 0);
			return false;
		}
		function beforeRemove(treeId, treeNode) {
			className = (className === "dark" ? "":"dark");
			showLog("[ "+getTime()+" beforeRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.selectNode(treeNode);
			return confirm("确认删除'" + treeNode.name + "'节点吗?");
		}
		function beforeRename(treeId, treeNode, newName, isCancel) {
			className = (className === "dark" ? "":"dark");
			showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" beforeRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
			if (newName.length == 0) {
				setTimeout(function() {
					var zTree = $.fn.zTree.getZTreeObj("treeDemo");
					zTree.cancelEditName();
					alert("Node name can not be empty.");
				}, 0);
				return false;
			}
			return true;
		}
		// 树的单击事件         
		    function zTreeOnClickRight(event, treeId, treeNode) {
		        var treeid = treeNode.id;
		        $("#hidId").val(treeid);
		
		        $("#ifm").attr("src", "FileView?NodeId=" + treeid);
		    }
		
		    function treeShow(data) {
		        zTreeObj = $.fn.zTree.init($("#test"), setting, data);
		        zTreeObj.expandAll(true);
		    }
//主动加载jquery模块
layui.use(['jquery', 'layer'], function(){
	var $ = layui.jquery //重点处
	,layer = layui.layer;
	table = layui.table;//表格，注意此处table必须是全局变量
	$(".treeDiv").height($('.body-right').height()-4);//树高度
	
	var arr = [[
	    {type:'checkbox'}
	  ,{field: 'name', title: '姓名'}
	  ,{field: 'sbmc', title: '部门'}
	  ,{field: 'pc', title: '卡号'}
	  ,{field: 'pc', title: '学工号'}
	  ,{fixed: 'right', title:'状态', toolbar: '#barDemo', width:150}
	  
	]];
	var limitArr =[10,20,30];
	var urls = '../../../tableJson.js';
	com.tableRender('#layui-table','tableId','full-53',limitArr,urls,arr);//加载表格,注意tableId是自定义的，在表格重载需要！！

    /*-----新增员工组-----*/
 	$("#addBtn").click(function(){	
	  com.pageOpen("新增员工组","html/cust-mgt/personGr-mgt/add.html",['930px', '520px']);
	})

	/*-----添加员工到组-----*/
	$("#addPersonBtn").click(function(){	
	  com.pageOpen("添加员工到组","html/cust-mgt/personGr-mgt/addPerson.html",['950px', '520px']);
	})
	
	/*-----详情-----*/
	$("#detailBtn").click(function(){	
	  com.checkOpen("详情","html/cust-mgt/personGr-mgt/detail.html",['930px', '520px']);
	})
	
	/*-----删除-----*/
	$("#delBtn").click(function(){	
		var ix = com.confirm2('员工仅会从组中移除，并不会被删除。确认将选中员工移出该组吗？','确认移出',['确认', '取消'],[],function(ix){
			 //do something
			parent.layer.close(ix);
		  com.reloadTable();
		  
		})
	});
	
	//监听行工具事件
	  table.on('tool(tableBox)', function(obj){
	    var data = obj.data;
	    console.log(obj)
	    if(obj.event === 'shouquan'){
	      com.pageOpen("已授权设备","html/cust-mgt/personGr-mgt/auth.html",['930px', '500px']);
	    } else if(obj.event === 'edit'){
	      
	    }
	  });

})	
</script>
</html>